/**
 * Created by Administrator on 2018/6/15.
 */


function showProInfo() {
    // var proId = $("#proId").val();

    $$scope.proId = $$scope.bid.projId;

    probox($$scope, $CertusFormAjax);
}
$CertusJsonAjax.ajax("queryBidProcessTrace",{
    "processInstanceId": $CertusJsonAjax.getProInstanceId(),
    "stepInstanceId": $CertusJsonAjax.getStepInstanceId()
},function(res){
    $$scope.processCCBXTrace = res.data;
})

$CertusJsonAjax.ajax("queryBidProcessTrace",{
    "processInstanceId": $CertusJsonAjax.getProInstanceId(),
    "stepInstanceId": $CertusJsonAjax.getStepInstanceId()
},function(res){
    $$scope.processs = res.data;
})

$CertusJsonAjax.ajax("bidBaseInfo",{
    "processInstanceId": $CertusJsonAjax.getProInstanceId(),
    "stepInstanceId": $CertusJsonAjax.getStepInstanceId()
},function(res){

    $$scope.bid =res.data;

    $$scope.bid.proName =res.data.projName;
    //项目 编号
    $$scope.bid.proNumber = res.data.proNumber;
    //项目区域
    $$scope.bid.proArea = res.data.proArea;
    //客户 名称
    $$scope.bid.customName= res.data.customName;
    //项目 编号
    $$scope.precedenceSelect = [
        {name:"低",precedence:1},
        {name:"中",precedence:2},
        {name:"高",precedence:3}
    ]
    $$scope.bid.precedence = res.data.precedence+"";
    $$scope.bid.deadlineDate = res.data.deadLineDate;
    // $$scope.

    $$scope.bid.processInstanceId =  $CertusJsonAjax.getProInstanceId();
    $$scope.bid.stepInstanceId =  $CertusJsonAjax.getStepInstanceId();
    var picker1 = $('#datetimeid').datetimepicker({
        format: 'YYYY-MM-DD',
        locale: moment.locale('zh-cn'),
    }).on('dp.change', function (e) {
        var result = new moment(e.date).format('YYYY-MM-DD');
        if(result && !angular.isUndefined(result)){
            $$scope.bid.deadlineDate= result;
            $$scope.$apply();
        }
    });
    $CertusJsonAjax.ajax('oldBaseInfo', {
        "processInstanceId": $CertusJsonAjax.getProInstanceId(),
        "stepInstanceId": $CertusJsonAjax.getStepInstanceId()
    }, function (res) {
        // $$scope.bid.opinionMsg = res.data.opinionMsg;
        $$scope.bid.oldOpinionMsg = res.data.oldOpinionMsg;
    })
});

$$scope.submit = function(){
    var regex = /[0-9a-zA-Z]*/g;
    if($$scope.bid.principalName && ""!=$$scope.bid.principalName){
        var numList = $$scope.bid.principalName.match(regex);
        $CertusFormAjax.ajax("confirmUserId",{name:numList.join().replace(",","") },function(res){
            if(res.data != "fail"){
                $$scope.bid.specifiedMan = res.data;
                $CertusJsonAjax.ajax("bidSubmit",$$scope.bid,function(res){
                    history.back();
                })
            }else{
                layer.msg("审批人,暂不存在");
            }
        })
    }else{
        layer.msg("请填写下级审批人");
    }
}


// function addBid($scope, $route, CertusFormAjax, CertusJsonAjax, $location, $http, $cookies,$routeParams){
//
//
//     $scope.bid = {};
//     //暂时 写死
//     $scope.bid.templateCode = "TBLC";
//
//
//
//
//     $scope.submitBid = function(){
//         CertusJsonAjax.ajax("bidCommit",this.bid,function(res){
//             history.back();
//         })
//     }
// }